package com.pds.web.testOrganization.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pds.common.utils.DateUtils;
import com.pds.common.utils.SecurityUtils;
import com.pds.web.testOrganization.domain.PdsTestOrganizationInspect;
import com.pds.web.testOrganization.mapper.PdsTestOrganizationInspectMapper;
import com.pds.web.testOrganization.service.IPdsTestOrganizationInspectService;
import com.pds.web.testOrganizationInfo.domain.PdsTestOrganizationInfo;
import com.pds.web.testOrganizationInfo.mapper.PdsTestOrganizationInfoMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service("pdsTestOrganizationInspectService")
public class PdsTestOrganizationInspectServiceImpl extends ServiceImpl<PdsTestOrganizationInspectMapper, PdsTestOrganizationInspect> implements IPdsTestOrganizationInspectService
{

    @Resource
    private PdsTestOrganizationInspectMapper pdsTestOrganizationInspectMapper;

    @Resource
    private PdsTestOrganizationInfoMapper pdsTestOrganizationInfoMapper;

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public PdsTestOrganizationInspect addInspect(PdsTestOrganizationInspect pdsTestOrganizationInspect) {

//        Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
//        PdsTestOrganizationInfo pdsTestOrganizationInfo = pdsTestOrganizationInfoMapper.selectByUserId(userId);
        Date createTime = DateUtils.parseDate(DateUtils.getTime());
        pdsTestOrganizationInspect.setCreateTime(createTime);
        pdsTestOrganizationInspect.setStatus("1");
//        pdsTestOrganizationInspect.setUserId(userId);
//        pdsTestOrganizationInspect.setOrganizationId(pdsTestOrganizationInfo.getId());
        pdsTestOrganizationInspectMapper.insertInspect(pdsTestOrganizationInspect);
        return pdsTestOrganizationInspect;
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public Boolean deleteInspect(Long id) {
        return pdsTestOrganizationInspectMapper.deleteInspect(id) > 0;
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public Boolean updateInspect(PdsTestOrganizationInspect pdsTestOrganizationInspect) {
        Date updateTime = DateUtils.parseDate(DateUtils.getTime());
        pdsTestOrganizationInspect.setUpdateTime(updateTime);
        return pdsTestOrganizationInspectMapper.updateInspect(pdsTestOrganizationInspect) > 0;
    }

    @Override
    public List<PdsTestOrganizationInspect> selectInspectlist(PdsTestOrganizationInspect pdsTestOrganizationInspect) {
        return pdsTestOrganizationInspectMapper.selectInspectlist(pdsTestOrganizationInspect);
    }
}
